package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /**
     * 分页查询
     */
    // @Select("select e.*,d.name as deptName from emp e left join dept d on e.dept_id=d.id order by update_time desc ")
    List<Emp> findAll(EmpQueryParam empQueryParam);

    /**
     * 新增员工
     * @param emp
     */
    //主键返回
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp(username,  name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void addEmp(Emp emp);


    @Select("select * from emp;")
    List<Emp> selectAll();

    void deleteBatch(List<Integer> ids);

    Emp getById(Integer id);

    void update(Emp emp);

    List<Map> getEmpJobData();


    List<Map> getEmpGenderData();

    @Select("select * from emp where username=#{username} and password=#{password} ;")
    Emp login(Emp emp);

    @Select("select password from emp where id=#{id};")
    String selectPwd(Integer id);

    @Update("update emp set password=#{newPassword} where id=#{id}")
    void updatePwd(Integer id ,String newPassword);
}
